import {formatMessage} from './intl';
import {message} from 'antd';

export const updateValidator = data => {
    const emptyErrors = [];
    const dealerSaleInformationDetails = data.dealerSaleInformationDetails;
    if(dealerSaleInformationDetails.some(d => !d.brandId))
        emptyErrors.push(
            formatMessage({
                id: 'validator.message.brandId',
                defaultMessage: '品牌'
            })
        );
    if(dealerSaleInformationDetails.some(d => !d.tradeMethodId))
        emptyErrors.push(
            formatMessage({
                id: 'validator.message.tradeMethodId',
                defaultMessage: '贸易方式'
            })
        );
    if(dealerSaleInformationDetails.some(d => !d.currency))
        emptyErrors.push(
            formatMessage({
                id: 'validator.message.currency',
                defaultMessage: '结算币种'
            })
        );
    if(dealerSaleInformationDetails.some(d => !d.priceClause))
        emptyErrors.push(
            formatMessage({
                id: 'validator.message.priceClause',
                defaultMessage: '价格条款'
            })
        );
    if(dealerSaleInformationDetails.some(d => !d.effectiveDate))
        emptyErrors.push(
            formatMessage({
                id: 'validator.message.effectiveDate',
                defaultMessage: '生效日期'
            })
        );
    if(emptyErrors.length > 0) {
        message.warning(`${emptyErrors.join('，')}${formatMessage({
            id: 'validator.required',
            defaultMessage: '必填!'
        })}`);
        return false;
    }
    return true;
};
